/*
 * @Author: your name
 * @Date: 2020-09-13 08:19:19
 * @LastEditTime: 2020-09-13 08:44:56
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \woniutaofang\lib\pages\index_page.dart
 */
import 'package:woniutaofang/components/ui/bubble_bottom_bar.dart';
import 'package:woniutaofang/pages/home/page/home_page.dart';
import 'package:woniutaofang/pages/house/house_page.dart';
import 'package:woniutaofang/pages/mine/page/mine_page.dart';
import 'package:woniutaofang/provider/currentIndex.dart';
import 'package:woniutaofang/utils/double_tap_back_exit_app.dart';
import 'package:woniutaofang/utils/theme_utils.dart';
import 'package:flutter/material.dart';

import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:provider/provider.dart';

class IndexPage extends StatelessWidget {
  final PageController _pageController = PageController();

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);
    return DoubleTapBackExitApp(
        child: Selector<CurrentIndexProvider, CurrentIndexProvider>(
      selector: (context, provider) => provider,
      shouldRebuild: (pre, next) => true,
      builder: (context, value, child) {
        return Container(
          child: Scaffold(
              // backgroundColor: Colors.grey,
              bottomNavigationBar: BubbleBottomBar(
                  opacity: 0.2,
                  currentIndex: value.currentIndex,
                  onTap: (int index) {
                    _pageController.jumpToPage(index);
                    Provider.of<CurrentIndexProvider>(context, listen: false)
                        .changeIndex(index);
                  },
                  borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
                  elevation: 8,
                  items: <BubbleBottomBarItem>[
                    BubbleBottomBarItem(
                        backgroundColor: Colors.red,
                        icon: Icon(Icons.home,
                            color: ThemeUtils.getIconColor(context)),
                        activeIcon: Icon(Icons.home, color: Colors.red),
                        title: Text("首页")),
                    BubbleBottomBarItem(
                        backgroundColor: Colors.deepPurple,
                        icon: Icon(Icons.dashboard,
                            color: ThemeUtils.getIconColor(context)),
                        activeIcon:
                            Icon(Icons.dashboard, color: Colors.deepPurple),
                        title: Text("新房")),
                    BubbleBottomBarItem(
                        backgroundColor: Colors.indigo,
                        icon: Icon(Icons.language,
                            color: ThemeUtils.getIconColor(context)),
                        activeIcon: Icon(Icons.language, color: Colors.indigo),
                        title: Text("我的")),
                  ]),
              body: PageView(
                physics: const NeverScrollableScrollPhysics(), // 禁止滑动
                controller: _pageController,
                onPageChanged: (int index) => {
                  Provider.of<CurrentIndexProvider>(context, listen: false)
                      .changeIndex(index)
                },
                children: <Widget>[HomePage(), HousePage(), MinePage()],
              )
              // IndexedStack(
              //     index: value.currentIndex,
              //     children: <Widget>[HomePage(), HousePage(), MinePage()]),
              ),
        );
      },
    ));
  }
}
